package com.vict.framework.pay.taskimpl;

import com.vict.framework.pay.entity.PayBack;
import com.vict.framework.pay.entity.PayOrder;
import com.vict.framework.pay.mapper.PayBackMapper;
import com.vict.framework.pay.mapper.PayOrderMapper;
import com.vict.framework.task.annotation.TaskConsumerConfiguration;
import com.vict.framework.task.bean.dto.Task;
import com.vict.framework.task.bean.dto.TaskConsumeResult;
import com.vict.framework.task.core.TaskExecute;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
@TaskConsumerConfiguration(type = PayBackTask.type, sameTimeWorkNum = 20,
    failRetryTimeSeconds={
        1*60, 2*60, 5*60, 10*60
    })
public class PayBackTask implements TaskExecute<String> {
    public static final String type = "PayBackTask";

    @Autowired
    private PayOrderMapper payOrderMapper;

    @Autowired
    private PayBackMapper payBackMapper;

    @Override
    public TaskConsumeResult doConsume(Task task, String payBackDtoId) {
        PayBack payBack = payBackMapper.selectById(payBackDtoId);
        PayOrder payOrder = payOrderMapper.selectById(payBack.getPayDtoId());

        if(payOrder.getPayType().equals(PayOrder.PayType.payType_cash)){
            // 现金支付退款
            // return framworkPayInnerService.cashPayBack(payBackItems, payOrderVO, now);
        }else if(payOrder.getPayType().equals(PayOrder.PayType.payType_WeiXin)){
            // 在线支付发起退款
            // return framworkPayInnerService.weiXinBack(payBackItems, payOrderVO, now);
        }else if(payOrder.getPayType().equals(PayOrder.PayType.payType_ZhiFuBao)){
            // 在线支付发起退款
            // return framworkPayInnerService.zhiFuBaoBack(payBackItems, payOrderVO, now);
        }else{
            throw new RuntimeException("未知异常");
        }

        return task.commitConsumer();
    }
}
